package app.util;

import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.util.resource.Resource;
/*
<dependency>  
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<version>2.2</version>
</dependency> 
	可以添加多个目录。第二个依赖只是测试包，这里不需要。
*/
public class SplitFileServer {

	public static void main(String[] args) throws Exception {
		
		Server server = new Server(8083);		
		
		ContextHandler context0 = new ContextHandler();
		context0.setContextPath("/");
		ResourceHandler resourceHandler0 = new ResourceHandler();
		resourceHandler0.setDirectoriesListed(true);
		resourceHandler0.setBaseResource(Resource.newResource("c:/"));
		context0.setHandler(resourceHandler0);
		
		ContextHandler context1 = new ContextHandler();
		context1.setContextPath("/");
		ResourceHandler resourceHandler1 = new ResourceHandler();
		resourceHandler1.setDirectoriesListed(true);
		resourceHandler1.setBaseResource(Resource.newResource("d:/"));
		context1.setHandler(resourceHandler1);
		
		ContextHandlerCollection contextHandlerCollection = new ContextHandlerCollection();
		contextHandlerCollection.setHandlers(new Handler[] {context0, context1});
		
		server.setHandler(contextHandlerCollection);
		server.start();
		System.out.println(server.dump());
	}
}
